﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;
using WuDada.Core.Post.Domain;
using System.Text;

public partial class news : System.Web.UI.Page
{
    private PostFactory m_PostFactory;
    private IPostService m_PostService;

    //最新消息 NodeId=4
    private int m_NodeId = 4;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_PostFactory = new PostFactory();
        m_PostService = m_PostFactory.GetPostService();

        if (!IsPostBack)
        {
            FillNews();
        }
    }

    private void FillNews()
    {
        Dictionary<string, string> conditions = new Dictionary<string, string>();
        conditions.Add("NodeId", m_NodeId.ToString());
        conditions.Add("Flag", "1");

        //分頁
        AspNetPager1.RecordCount = m_PostService.GetPostCount(conditions);
        int pageIndex = (AspNetPager1.CurrentPageIndex - 1);
        int pageSize = AspNetPager1.PageSize;
        conditions.Add("PageIndex", pageIndex.ToString());
        conditions.Add("PageSize", pageSize.ToString());

        IList<PostVO> postList = m_PostService.GetPostList(conditions);
        StringBuilder sb = new StringBuilder();

        if (postList != null && postList.Count > 0)
        {
            int i = 1;
            foreach (PostVO postVO in postList)
            {
                string strClass = ((i % 2) == 0) ? "News-Day2" : "News-Day1";
                string strClass2 = ((i % 2) == 0) ? "News-Name2" : "News-Name1";
                sb.AppendFormat("<tr><td width='98' valign='middle' class='{0}'>{1}</td><td width='732' valign='middle' class='{2}'><a href='news_in.aspx?id={3}' class='whitebtn'>{4}</a></td></tr>"
                    , strClass, postVO.ShowDate.Value.ToString("yyyy.MM.dd"), strClass2, postVO.PostId, postVO.Title);
                i++;
            }
        }

        ltlList.Text = sb.ToString();
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        FillNews();
    }

}